package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zr.dao.SqspDaoljc;
import com.zr.model.SQ;
import com.zr.model.Teacher;
import com.zr.util.JDBCUtil;

public class SqspDaoImplljc implements SqspDaoljc{
	//获取所有的申请请求  SQ为申请
	@Override
	public List<SQ> getAllSQ(int page,int rows) {
		List<SQ> sq = new ArrayList<>();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT applyscore.cname,applyscore.id,applyscore.nr,applyscore.sid,applyscore.sj,");
		sql.append(" applyscore.tname,applyscore.zt,applyscore.score FROM applyscore");
		sql.append(" LIMIT ?,?");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, (page-1)*rows);
			pst.setInt(2, rows);
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				SQ s = new SQ();
				s.setCname(rs.getString("cname"));
				s.setNr(rs.getString("nr"));
				s.setSid(rs.getInt("sid"));
				s.setSj(rs.getString("sj"));
				s.setTname(rs.getString("tname"));
				s.setZt(rs.getString("zt"));
				s.setScore(rs.getString("score"));
				s.setId(rs.getInt("id"));
				sq.add(s);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sq;
	}
	
	
	//获取申请的总条数
	@Override
	public int getCountSQ() {
		int count = 0;
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT COUNT(applyscore.id) as count ");
		sql.append(" FROM applyscore");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				count =Integer.parseInt(rs.getString("count"));
			}	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}

}
